package org.dromara.system.controller.business;

import lombok.RequiredArgsConstructor;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.dromara.system.domain.vo.OrderSalesDataImportVo;
import org.dromara.system.listener.OrderSalesDataListener;
import org.dromara.system.service.ISalesDataService;
import org.dromara.common.excel.core.ExcelResult;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.system.domain.vo.OrderSalesDataVo;
import org.dromara.system.domain.bo.OrderSalesDataBo;
import org.dromara.system.service.IOrderSalesDataService;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 订单销售数据信息
 *
 * @author joker
 * @date 2025-05-05
 */

@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/orderSalesData")
public class OrderSalesDataController extends BaseController {

    private final IOrderSalesDataService orderSalesDataService;
    private final ISalesDataService salesDataService;

    /**
     * 查询订单销售数据信息列表
     */
    @SaCheckPermission("system:orderSalesData:list")
    @GetMapping("/list")
    public TableDataInfo<OrderSalesDataVo> list(OrderSalesDataBo bo, PageQuery pageQuery) {
        return orderSalesDataService.queryPageList(bo, pageQuery);
    }

    /**
     * 导入数据
     *
     * @param file 导入文件
     */
    @Log(title = "订单销售数据信息", businessType = BusinessType.IMPORT)
    @SaCheckPermission("system:orderSalesData:import")
    @PostMapping(value = "/importData", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public R<Void> importData(@RequestPart("file") MultipartFile file) throws Exception {
        ExcelResult<OrderSalesDataImportVo> result = ExcelUtil.importExcel(file.getInputStream(), OrderSalesDataImportVo.class, new OrderSalesDataListener());
        return R.ok(result.getAnalysis());
    }

}
